﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EnterpriseFund.Common;
using System.Data;
using DevExpress.Web.Mvc;
using Newtonsoft.Json;
using System.Reflection;
using DevExpress.XtraReports.UI;
using DevExpress.XtraPrinting;

namespace EnterpriseFund.Controllers
{
        [OutputCache(Duration = 0, VaryByParam = "none")] 
    public class TaxAuditFormController : AdminBaseController
    {
        //
        // GET: /TaxAuditForm/
        [AuthorityActionFilter("m_TaxAuditForm", Order = 1)]
        [LogPageActionFilter("数据审核", Order = 2)]
        public ActionResult Index()
        {
            string strwhere = " FStatus='0' ";
            List<Model.TaxAuditForm> taxAuditFormList = new List<Model.TaxAuditForm>();
            taxAuditFormList = GetTaxAuditFormListList(strwhere, 1);
            OperateSession.del("TaxAuditAdjustList");
            return View(taxAuditFormList);
        }

        public ActionResult TaxAuditFormListPartial()
        {
            int pageIndex = Request.Params["pageIndex"] == null ? 0 : int.Parse(Request.Params["pageIndex"].ToString());
            int pageCount = Request.Params["PageCount"] == null ? 0 : int.Parse(Request.Params["PageCount"].ToString());
            int pageRowSize = Request.Params["pageRowSize"] == null ? 0 : int.Parse(Request.Params["pageRowSize"].ToString());
            int pageRowCount = Request.Params["pageRowCount"] == null ? 0 : int.Parse(Request.Params["pageRowCount"].ToString());
            string callbackArg = DevExpressHelper.CallbackArgument;

            string command = Request.Params["command"] == null ? "" : Request.Params["command"].ToString();

            if (command == "PAGERONCLICK")
            {
                string[] args = callbackArg.Split(new char[1] { '|' });
                string arg = args[args.Count() - 1];

                switch (arg)
                {
                    case "PBN;":
                        {
                            //下一页
                            pageIndex = pageIndex + 2;
                            break;
                        }
                    case "PBP;":
                        {
                            //上一页
                            //pageIndex = pageIndex;
                            break;
                        }
                    case "PBL;":
                        {
                            //最后一页
                            pageIndex = pageCount;
                            break;
                        }
                    case "PBF;":
                        {
                            //第一页
                            pageIndex = 1;
                            break;
                        }
                    default:
                        {
                            //点击数字页码
                            string tempIndex = arg.Replace("PN", "");
                            tempIndex = tempIndex.Replace(";", "");
                            if (RegExp.IsNumeric(tempIndex))
                            {
                                pageIndex = int.Parse(tempIndex) + 1;
                            }
                            break;
                        }

                }
            }
            else
            {
                pageIndex = pageIndex + 1;
            }
            string strwhere = " FStatus='0' ";


            //string NSRMC = Request.Params["NSRMC"];
            //string NSRBM = Request.Params["NSRBM"];
            //string HY_DM = Request.Params["HY_DM"];
            //string FEnterprisePropNo = Request.Params["FEnterprisePropNo"];
            //string FFinancePropNo = Request.Params["FFinancePropNo"];
            //string IsNoFull = Request.Params["IsNoFull"];

            BLL.TaxAuditForm taxAuditFormBLL = new BLL.TaxAuditForm();
            List<Model.TaxAuditForm> taxAuditFormList = new List<Model.TaxAuditForm>();
            taxAuditFormList = GetTaxAuditFormListList(strwhere, pageIndex);
            return PartialView("TaxAuditFormListPartial", taxAuditFormList);
        }

        /// <summary>
        /// 获取定义的工作时间数据
        /// </summary>
        /// <param name="strWhere">查询条件</param>
        /// <param name="pageIndex">第几页</param>
        /// <returns>查询出来的数据</returns>
        private List<Model.TaxAuditForm> GetTaxAuditFormListList(string strWhere, int pageIndex)
        {
            BLL.Common commonBll = new BLL.Common();
            BLL.TaxAuditForm taxAuditFormBLL = new BLL.TaxAuditForm();
            string fiedls = "FTaxAuditId";
            int total;
            DataSet ds = commonBll.GetListByPage("fund.[fn_TaxAuditForm](" + OperateSession.get(GlobalConstant.PARAM_SYSYEAR) + ")", fiedls, Common.GlobalConstant.CONSTRING_PAGESIZE, pageIndex, strWhere, "FTaxAuditId", out total);
            List<Model.TaxAuditForm> taxAuditFormList = taxAuditFormBLL.DataTableToList(ds.Tables[0]);
            List<Model.TaxAuditForm> taxAuditFormAllList = new List<Model.TaxAuditForm>();
            total = taxAuditFormBLL.GetRecordCount(strWhere, OperateSession.get(GlobalConstant.PARAM_SYSYEAR));
            int pageRowSize = Common.GlobalConstant.CONSTRING_PAGESIZE;
            for (int i = 0; i < total; i++)
            {
                taxAuditFormAllList.Add(null);
            }
            for (int i = 0; i < pageRowSize; i++)
            {
                if (taxAuditFormList.Count > i)
                {
                    taxAuditFormAllList[((pageIndex - 1) * pageRowSize) + i] = taxAuditFormList[i];
                }
            }

            return taxAuditFormAllList;
        }


        /// <summary>
        /// 税款审核显示数据列表
        /// </summary>
        /// <param name="taxAuditAdjustList">调整列表</param>
        /// <param name="showdt">税款列表</param>
        /// <param name="year">年度</param>
        /// <returns></returns>
        public DataTable GetShowDate(List<Model.TaxAuditAdjust> taxAuditAdjustList, DataTable showdt, string year)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("cz");
            dt.Columns.Add("FTaxClassAllowanceNo");
            dt.Columns.Add("FTaxClassAllowanceName");
            dt.Columns.Add("se",typeof(decimal));
            dt.Columns.Add("FAdjustAmount",typeof(decimal));
            dt.Columns.Add("sumse", typeof(decimal));
            dt.Columns.Add("FDataSource");

            ///调整税款计算各可补贴税种合计
            var Adjustq = (from nm in taxAuditAdjustList
                           group nm by new { t1 = nm.FTaxClassAllowanceNo }
                               into g
                               select new
                               {
                                   FTaxClassAllowanceNo = g.Key.t1,
                                   sumse = g.Sum(p => p.FAdjustAmount)
                               }
                             );

            ///税款计算各可补贴税种合计
            var q = (from nm in showdt.AsEnumerable()
                     group nm by new { t1 = nm.Field<string>("FTaxClassAllowanceNo"), t2 = nm.Field<string>("FDataSource"), t3 = nm.Field<string>("FTaxClassAllowanceName") }
                         into g
                         select new
                         {
                             FTaxClassAllowanceNo = g.Key.t1,
                             FTaxClassAllowanceName = g.Key.t3,
                             FDataSource = g.Key.t2,
                             SumSe = g.Sum(p => p.Field<decimal?>("se"))
                         });

            BLL.TaxClassAllowance taxClassAllowanceBLL = new BLL.TaxClassAllowance();
            List<Model.TaxClassAllowance> taxClassAllowanceList = taxClassAllowanceBLL.GetModelList(" FYear=" + year);
            if (taxClassAllowanceList.Count > 0)
            {
                foreach (Model.TaxClassAllowance model in taxClassAllowanceList)
                {
                    DataRow dr = dt.NewRow();
                    dr["FTaxClassAllowanceNo"] = model.FTaxClassAllowanceNo;
                    dr["FTaxClassAllowanceName"] = model.FTaxClassAllowanceName;
                    foreach (var c in q)
                    {
                        if (c.FTaxClassAllowanceNo == model.FTaxClassAllowanceNo)
                        {
                            if (c.SumSe != null)
                            {
                                dr["se"] = decimal.Round(decimal.Parse(c.SumSe.ToString()), 0);
                            }
                            dr["FDataSource"] = c.FDataSource;
                        }
                    }
                    foreach (var Aq in Adjustq)
                    {
                        if (Aq.FTaxClassAllowanceNo == model.FTaxClassAllowanceNo)
                        {
                            dr["FAdjustAmount"] = Aq.sumse.ToString("f2");
                            if (dr["FDataSource"] == null || dr["FDataSource"].ToString() == "")
                            {
                                dr["FDataSource"] = "DS";
                            }
                        }
                    }
                    if (dr["FAdjustAmount"] == null || dr["FAdjustAmount"].ToString() == "")
                    {
                        dr["FAdjustAmount"] = 0;
                    }
                    if (dr["se"] == null || dr["se"].ToString() == "")
                    {
                        dr["se"] = 0;
                    }
                    dr["cz"] = "mx";
                    dt.Rows.Add(dr);
                }

                //int z = dt.Rows.Count;
                //for (int i = 0; i < z; i++)
                //{
                //    if (dt.Rows[i]["FDataSource"] == null || dt.Rows[i]["FDataSource"].ToString() == "")
                //    {
                //        dt.Rows.Remove(dt.Rows[i]);
                //    }
                //}

                var dta = (from nm in dt.AsEnumerable() where nm.Field<string>("FDataSource") != null && nm.Field<string>("FDataSource") != "" select nm);
                if (dta.Count() > 0)
                {
                    dt = dta.CopyToDataTable();
                }
                var typeq = (from nm in dt.AsEnumerable()
                             group nm by new { t1 = nm.Field<string>("FDataSource") }
                                 into g
                                 select new
                                 {
                                     FDataSource = g.Key.t1,
                                     SumSe = g.Sum(p => p.Field<decimal?>("se")),
                                     TZSumSe = g.Sum(p => p.Field<decimal?>("FAdjustAmount"))
                                 });

                decimal sumse = dt.AsEnumerable().Sum(p => p.Field<decimal>("se"));
                decimal sumAdjustAmount = dt.AsEnumerable().Sum(p => p.Field<decimal>("FAdjustAmount"));
                foreach (var t in typeq)
                {
                    DataRow dr = dt.NewRow();
                    dr["FTaxClassAllowanceNo"] = "";
                    dr["FTaxClassAllowanceName"] = "";
                    dr["se"] = t.SumSe;
                    dr["FAdjustAmount"] = t.TZSumSe;
                    switch (t.FDataSource)
                    {
                        case "GS":
                            dr["cz"] = "国税合计";
                            break;
                        case "DS":
                            dr["cz"] = "地税合计";
                            break;
                    }
                   
                    dt.Rows.Add(dr);
                }

                DataRow sondr = dt.NewRow();
                sondr["FTaxClassAllowanceNo"] = "";
                sondr["FTaxClassAllowanceName"] = "";
                sondr["se"] = sumse;
                sondr["FAdjustAmount"] = sumAdjustAmount;
                sondr["cz"] = "总计";
                dt.Rows.Add(sondr);
                foreach (DataRow dr in dt.Rows)
                {
                    switch (dr["FDataSource"].ToString())
                    {
                        case "GS":
                            dr["FDataSource"] = "国税";
                            break;
                        case "DS":
                            dr["FDataSource"] = "地税";
                            break;
                    }
                   
                }
                dt.Columns["sumse"].Expression = "se+FAdjustAmount";
            }
            return dt;
        }

        public ActionResult TaxAuditFormShowDate(string NSRBM, string beginDate, string endDate)
        {
            Model.DJ_NSRXX DJ_NSRXXModel = new Model.DJ_NSRXX();
            DataTable dt = new DataTable();
            ViewData["NSRBM"] = NSRBM;
            ViewData["beginDate"] = beginDate;
            ViewData["endDate"] = endDate;
            if (NSRBM != null && NSRBM != "" && beginDate != null && beginDate != "" && endDate != null && endDate != "")
            {
                BLL.DJ_NSRXX DJ_NSRXXBLL = new BLL.DJ_NSRXX();
                //DJ_NSRXXModel = DJ_NSRXXBLL.GetModelByNSRBM(NSRBM, DateTime.Parse(beginDate).Year.ToString());

                DataSet ds = DJ_NSRXXBLL.GetDataforAudit(beginDate, endDate, DateTime.Parse(beginDate).Year.ToString(), NSRBM);

                List<Model.TaxAuditAdjust> taxAuditAdjustlist = OperateSession.getList<Model.TaxAuditAdjust>("TaxAuditAdjustList");

                if (taxAuditAdjustlist == null)
                {
                    taxAuditAdjustlist = new List<Model.TaxAuditAdjust>();
                }

                dt = GetShowDate(taxAuditAdjustlist, ds.Tables[0], DateTime.Parse(beginDate).Year.ToString());
            }
            else
            {
                DJ_NSRXXModel = new Model.DJ_NSRXX();
                dt.Columns.Add("cz");
                dt.Columns.Add("FTaxClassAllowanceNo");
                dt.Columns.Add("FTaxClassAllowanceName");
                dt.Columns.Add("se");
                dt.Columns.Add("FAdjustAmount");
                dt.Columns.Add("sumse");
                dt.Columns.Add("FDataSource");
                ViewData["showDate"] = dt;
            }
            return View(dt);
        }


        public ActionResult TaxAuditFormAdd(string NSRBM, string beginDate, string endDate)
        {
            Model.DJ_NSRXX DJ_NSRXXModel = new Model.DJ_NSRXX();
            DataTable dt = new DataTable();
            if (NSRBM != null && NSRBM != "")
            {
                if (beginDate != null && beginDate != "")
                {
                    if (endDate != null && endDate != "")
                    {
                        OperateSession.add("TaxAuditFromEndData", endDate);
                        OperateSession.add("TaxAuditFromBeginDate", beginDate);
                        BLL.DJ_NSRXX DJ_NSRXXBLL = new BLL.DJ_NSRXX();
                        DJ_NSRXXModel = DJ_NSRXXBLL.GetModelByNSRBM(NSRBM, DateTime.Parse(beginDate).Year.ToString());
                        BLL.TaxAuditForm taxAuditFormBLL = new BLL.TaxAuditForm();
                        if (DJ_NSRXXModel != null)
                        {
                            BLL.YGZAllowance YGZAllowanceBLL = new BLL.YGZAllowance();
                            List<Model.YGZAllowance> AllYGZAllowanceList = YGZAllowanceBLL.GetModelList(" NSRDZDAH= " + DJ_NSRXXModel.NSRDZDAH);
                            if (AllYGZAllowanceList.Count > 0)
                            {
                                var q = (from nm in AllYGZAllowanceList group nm by nm.FYear into g select new { FYear = g.Key, sum = g.Sum(s => s.FAmount) });
                                string ygzbzStr = "该企业存在营改增补助：";

                                foreach (var n in q)
                                {
                                    ygzbzStr += n.FYear + "年" + n.sum + "元     ";
                                }
                                ViewData["ygzbzStr"] = ygzbzStr;
                            }
                            else
                            {
                                ViewData["ygzbzStr"] = "";
                            }

                            if (taxAuditFormBLL.ExistsAuditByNsbm2(DJ_NSRXXModel.NSRDZDAH.ToString()))
                            {
                                DJ_NSRXXModel = new Model.DJ_NSRXX();
                                NSRBM = "";
                                beginDate = "";
                                endDate = "";
                                ViewData["jsAlert"] = "该企业存在一条未操作完成数据，请核对后继续操作！";
                            }
                            //else if (taxAuditFormBLL.ExistsAuditByNsbm(DJ_NSRXXModel.NSRDZDAH.ToString(), beginDate, endDate))
                            //{
                            //    DJ_NSRXXModel = new Model.DJ_NSRXX();
                            //    NSRBM = "";
                            //    beginDate = "";
                            //    endDate = "";
                            //    ViewData["jsAlert"] = "该企业该时间段内已存在审核记录，请核对后继续操作！";
                            //}

                            else if (DJ_NSRXXModel.FEnterprisePropNo == "" && DJ_NSRXXModel.FFinancePropNo == "")
                            {
                                DJ_NSRXXModel = new Model.DJ_NSRXX();
                                NSRBM = "";
                                beginDate = "";
                                endDate = "";
                                ViewData["jsAlert"] = "该企业未设置企业性质或经济性质，请设置完毕后继续操作！";

                            }
                        }
                        else
                        {
                            DJ_NSRXXModel = new Model.DJ_NSRXX();
                            NSRBM = "";
                            beginDate = "";
                            endDate = "";
                            ViewData["jsAlert"] = "找不到该企业请核对后继续操作！";
                        }


                    }
                    else
                    {
                        DJ_NSRXXModel = new Model.DJ_NSRXX();
                        ViewData["jsAlert"] = "请选择入库日期！";
                    }
                }
                else
                {
                    DJ_NSRXXModel = new Model.DJ_NSRXX();
                    ViewData["jsAlert"] = "请选择入库日期！";
                }
                // DataSet ds = DJ_NSRXXBLL.GetDataforAudit(beginDate, endDate, DateTime.Parse(beginDate).Year.ToString(), NSRBM);

                // ViewData["showDate"] = GetShowDate(new List<Model.TaxAuditAdjust>(), ds.Tables[0], DateTime.Parse(beginDate).Year.ToString());
            }
            else
            {
                DJ_NSRXXModel = new Model.DJ_NSRXX();
            }
            if (beginDate != null && beginDate != "")
            {
                BLL.TaxClassAllowance TaxClassAllowanceBLL = new BLL.TaxClassAllowance();
                List<Model.TaxClassAllowance> tl = TaxClassAllowanceBLL.GetModelList(" FYear=" + DateTime.Parse(beginDate).Year.ToString());
                if (tl.Count > 0)
                {

                }
                else
                {
                    DJ_NSRXXModel = new Model.DJ_NSRXX();
                    NSRBM = "";
                    beginDate = "";
                    endDate = "";
                    ViewData["jsAlert"] = "请设置补贴类型！";
                }
            }


            string beginDates = OperateSession.get("TaxAuditFromBeginDate");
            string endDates = OperateSession.get("TaxAuditFromEndData");
            string FAllowanceClassNo = OperateSession.get("TaxAuditFromFAllowanceClassNo");
            ViewData["NSRBM"] = DJ_NSRXXModel.NSRBM;
            ViewData["beginDate"] = beginDates;
            ViewData["endDate"] = endDates;
            ViewData["FAllowanceClassNo"] = FAllowanceClassNo;
            ViewData["type"] = "ADD";
            BLL.AllowanceClass allowanceClassBLL = new BLL.AllowanceClass();
            ViewData["AllowanceClassList"] = allowanceClassBLL.GetModelList("");
            BLL.TaxAuditAdjust taxAuditAdjustBLL = new BLL.TaxAuditAdjust();
            List<Model.TaxAuditAdjust> taxAuditAdjustList = taxAuditAdjustBLL.GetLastAdjustList(DJ_NSRXXModel.NSRDZDAH.ToString());
            OperateSession.del("TaxAuditAdjustList");
            OperateSession.addList<Model.TaxAuditAdjust>("TaxAuditAdjustList", taxAuditAdjustList);
            return View("TaxAuditFormAdd", DJ_NSRXXModel);
        }

        public ActionResult TaxAuditFormEdit(string taxAuditId)
        {
            ViewData["FTaxAuditId"] = taxAuditId;

            BLL.TaxAuditForm taxAuditFormBLL = new BLL.TaxAuditForm();
            Model.TaxAuditForm taxAuditFormModel = taxAuditFormBLL.GetModel(taxAuditId);
            
            Model.DJ_NSRXX DJ_NSRXXModel = new Model.DJ_NSRXX();
            DataTable dt = new DataTable();

            BLL.DJ_NSRXX DJ_NSRXXBLL = new BLL.DJ_NSRXX();
            DJ_NSRXXModel = DJ_NSRXXBLL.GetModel(taxAuditFormModel.NSRDZDAH, taxAuditFormModel.FYear.ToString());

            // DataSet ds = DJ_NSRXXBLL.GetDataforAudit(beginDate, endDate, DateTime.Parse(beginDate).Year.ToString(), NSRBM);

            // ViewData["showDate"] = GetShowDate(new List<Model.TaxAuditAdjust>(), ds.Tables[0], DateTime.Parse(beginDate).Year.ToString());
            ViewData["FAllowanceClassNo"] = taxAuditFormModel.FAllowanceClassNo;
            ViewData["NSRBM"] = DJ_NSRXXModel.NSRBM;
            ViewData["beginDate"] = taxAuditFormModel.RKRQ_Q;
            ViewData["endDate"] = taxAuditFormModel.RKRQ_Z;
            ViewData["type"] = "EDIT";
            BLL.AllowanceClass allowanceClassBLL = new BLL.AllowanceClass();
            ViewData["AllowanceClassList"] = allowanceClassBLL.GetModelList("");
            OperateSession.del("TaxAuditAdjustList");
            return View("TaxAuditFormEdit",DJ_NSRXXModel);
        }

        public ActionResult TaxAuditFormSave()
        {
            Model.DJ_NSRXX DJ_NSRXXModel = new Model.DJ_NSRXX();
            string type = Fetch.Post("hidType");
            BLL.AllowanceClass allowanceClassBLL = new BLL.AllowanceClass();
            BLL.TaxAuditForm taxAuditFormBLL = new BLL.TaxAuditForm();
            List<Model.TaxAuditAdjust> taxAuditAdjustList = new List<Model.TaxAuditAdjust>();
            List<Model.TaxAudit_SB_ZSXX> taxAudit_SB_ZSXXList = new List<Model.TaxAudit_SB_ZSXX>();
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            string beginDate = Fetch.Post("hidBeginDate");
            string endDate = Fetch.Post("hidEndDate");
            string NSRBM = Fetch.Post("hidNSRBM");
            string status = Fetch.Post("hidFStatus");

            OperateSession.add("TaxAuditFromFAllowanceClassNo", DevExpress.Web.Mvc.ComboBoxExtension.GetValue<string>("FAllowanceClassNo"));

            BLL.DJ_NSRXX DJ_NSRXXBLL = new BLL.DJ_NSRXX();
            Model.TaxAuditForm taxAuditFormModel = new Model.TaxAuditForm();

            switch (type)
            {
                case "ADD":
                    try
                    {
                        taxAuditAdjustList = new List<Model.TaxAuditAdjust>();
                        taxAuditAdjustList = OperateSession.getList<Model.TaxAuditAdjust>("TaxAuditAdjustList");

                        taxAudit_SB_ZSXXList = new List<Model.TaxAudit_SB_ZSXX>();

                        ds = taxAuditFormBLL.GetDataforAuditForSave(beginDate, endDate, DateTime.Parse(beginDate).Year.ToString(), NSRBM);

                        dt = ds.Tables[0];
                        dt.Columns.Add("SB_ZSXX_ID");
                        dt.Columns.Add("FTaxAuditId");
                        dt.Columns.Add("FYear");

                        foreach (DataRow dr in dt.Rows)
                        {
                            Model.TaxAudit_SB_ZSXX taxAudit_SB_ZSXXModel = new Model.TaxAudit_SB_ZSXX();
                            PropertyInfo[] propertys = taxAudit_SB_ZSXXModel.GetType().GetProperties();
                            foreach (PropertyInfo pi in propertys)
                            {
                                string tempName = pi.Name;
                                if (dt.Columns.Contains(tempName))
                                {
                                    if (dr[tempName] != null && dr[tempName] != DBNull.Value)
                                    {
                                        if (pi.PropertyType == typeof(decimal))
                                        {
                                            pi.SetValue(taxAudit_SB_ZSXXModel, decimal.Parse(dr[tempName].ToString()), null);
                                        }
                                        else
                                        {
                                            pi.SetValue(taxAudit_SB_ZSXXModel, dr[tempName], null);
                                        }
                                    }
                                }
                            }
                            taxAudit_SB_ZSXXModel.FYear = DateTime.Parse(beginDate).Year;
                            taxAudit_SB_ZSXXList.Add(taxAudit_SB_ZSXXModel);
                        }

                        DJ_NSRXXModel = DJ_NSRXXBLL.GetModelByNSRBM(NSRBM, DateTime.Parse(beginDate).Year.ToString());

                        taxAuditFormModel.RKRQ_Q = DateTime.Parse(beginDate);
                        taxAuditFormModel.RKRQ_Z = DateTime.Parse(endDate);
                        taxAuditFormModel.NSRMC = DJ_NSRXXModel.NSRMC;
                        taxAuditFormModel.NSRDZDAH = DJ_NSRXXModel.NSRDZDAH;
                        taxAuditFormModel.FAllowanceClassNo = DevExpress.Web.Mvc.ComboBoxExtension.GetValue<string>("FAllowanceClassNo");
                        taxAuditFormModel.FEntityNo = GlobalConstant.ENTITYNO;
                        taxAuditFormModel.FInsDate = DateTime.Now;
                        taxAuditFormModel.FInsDeptNo = OperateSession.get(GlobalConstant.PARAM_DEPTNO);
                        taxAuditFormModel.FInsEmpNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);
                        taxAuditFormModel.FInsIP = GenerateUtil.GetClientIPv4Address();
                        taxAuditFormModel.FOldEnterprisePropNo = DJ_NSRXXModel.FEnterprisePropNo;
                        taxAuditFormModel.FOldFinancePropNo = DJ_NSRXXModel.FFinancePropNo;
                        taxAuditFormModel.FNewEnterprisePropNo = DJ_NSRXXModel.FEnterprisePropNo;
                        taxAuditFormModel.FNewFinancePropNo = DJ_NSRXXModel.FFinancePropNo;
                        switch (status)
                        {
                            case "Save":
                                foreach (Model.TaxAuditAdjust tAA in taxAuditAdjustList)
                                {
                                    tAA.FStatus = "N";
                                    tAA.FYear = DateTime.Parse(beginDate).Year;
                                    tAA.FAdjustDate = DateTime.Now;
                                }
                                taxAuditFormModel.FStatus = "0";
                                break;
                            case "open":
                                foreach (Model.TaxAuditAdjust tAA in taxAuditAdjustList)
                                {
                                    tAA.FStatus = "S";
                                    tAA.FYear = DateTime.Parse(beginDate).Year;
                                    tAA.FAdjustDate = DateTime.Now; 
                                }
                                taxAuditFormModel.FStatus = "1";
                                break;
                        }
                        taxAuditFormModel.FIsReturn = "N";
                        taxAuditFormModel.FYear = DateTime.Parse(beginDate).Year;
                        string id = taxAuditFormBLL.Add(taxAuditFormModel, taxAuditAdjustList, taxAudit_SB_ZSXXList);
                        //ViewData["NSRBM"] = NSRBM;
                        //ViewData["beginDate"] = beginDate;
                        //ViewData["endDate"] = endDate;
                        ViewData["AllowanceClassList"] = allowanceClassBLL.GetModelList("");
                        ViewData["jsAlert"] = "操作成功";
                        ViewData["NSRBM"] = "";
                        ViewData["beginDate"] = "";
                        ViewData["endDate"] = "";
                        if (status == "open")
                        {
                            WorkFlow("t_TaxAuditForm", "10", id, "start", "");
                        }
                        else
                        {
                            ViewData["FStatus"] = "Save";
                            return TaxAuditFormEdit(id);
                        }
                        return TaxAuditFormAdd("","","");
    
                    }
                    catch
                    {
                        //ViewData["NSRBM"] = NSRBM;
                        //ViewData["beginDate"] = beginDate;
                        //ViewData["endDate"] = endDate;
                        //ViewData["type"] = type;
                        //ViewData["AllowanceClassList"] = allowanceClassBLL.GetModelList("");
                        ViewData["jsAlert"] = "操作异常";
                        return TaxAuditFormAdd(NSRBM, beginDate, endDate);
                    }
                case "EDIT":
                    try
                    {
                        taxAuditAdjustList = OperateSession.getList<Model.TaxAuditAdjust>("TaxAuditAdjustList");

                        ds = taxAuditFormBLL.GetDataforAuditForSave(beginDate, endDate, DateTime.Parse(beginDate).Year.ToString(), NSRBM);

                        dt = ds.Tables[0];
                        dt.Columns.Add("SB_ZSXX_ID");
                        dt.Columns.Add("FTaxAuditId");
                        dt.Columns.Add("FYear");

                        foreach (DataRow dr in dt.Rows)
                        {
                            Model.TaxAudit_SB_ZSXX taxAudit_SB_ZSXXModel = new Model.TaxAudit_SB_ZSXX();
                            PropertyInfo[] propertys = taxAudit_SB_ZSXXModel.GetType().GetProperties();
                            foreach (PropertyInfo pi in propertys)
                            {
                                string tempName = pi.Name;
                                if (dt.Columns.Contains(tempName))
                                {
                                    if (dr[tempName] != null && dr[tempName] != DBNull.Value)
                                    {
                                        if (pi.PropertyType == typeof(decimal))
                                        {
                                            pi.SetValue(taxAudit_SB_ZSXXModel, decimal.Parse(dr[tempName].ToString()), null);
                                        }
                                        else
                                        {
                                            pi.SetValue(taxAudit_SB_ZSXXModel, dr[tempName], null);
                                        }
                                    }
                                }
                            }
                            taxAudit_SB_ZSXXModel.FYear = DateTime.Parse(beginDate).Year;
                            taxAudit_SB_ZSXXList.Add(taxAudit_SB_ZSXXModel);
                        }


                        DJ_NSRXXModel = DJ_NSRXXBLL.GetModelByNSRBM(NSRBM, DateTime.Parse(beginDate).Year.ToString());
                        taxAuditFormModel.FTaxAuditId = Fetch.Post("hidFTaxAuditId");
                        taxAuditFormModel.RKRQ_Q = DateTime.Parse(beginDate);
                        taxAuditFormModel.RKRQ_Z = DateTime.Parse(endDate);
                        taxAuditFormModel.NSRMC = DJ_NSRXXModel.NSRMC;
                        taxAuditFormModel.NSRDZDAH = DJ_NSRXXModel.NSRDZDAH;
                        taxAuditFormModel.FAllowanceClassNo = DevExpress.Web.Mvc.ComboBoxExtension.GetValue<string>("FAllowanceClassNo");
                        taxAuditFormModel.FEntityNo = GlobalConstant.ENTITYNO;
                        taxAuditFormModel.FUpdDate = DateTime.Now;
                        taxAuditFormModel.FUpdDeptNo = OperateSession.get(GlobalConstant.PARAM_DEPTNO);
                        taxAuditFormModel.FUpdEmplNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);
                        taxAuditFormModel.FUpdIP = GenerateUtil.GetClientIPv4Address();
                        taxAuditFormModel.FOldEnterprisePropNo = DJ_NSRXXModel.FEnterprisePropNo;
                        taxAuditFormModel.FOldFinancePropNo = DJ_NSRXXModel.FFinancePropNo;
                        switch (status)
                        {
                            case "Save":
                                taxAuditFormModel.FStatus = "0";
                                foreach (Model.TaxAuditAdjust tAA in taxAuditAdjustList)
                                {
                                    tAA.FStatus = "N";
                                    tAA.FYear = DateTime.Parse(beginDate).Year;
                                }
                                break;
                            case "open":
                                foreach (Model.TaxAuditAdjust tAA in taxAuditAdjustList)
                                {
                                    tAA.FStatus = "S";
                                    tAA.FYear = DateTime.Parse(beginDate).Year;
                                }
                                taxAuditFormModel.FStatus = "1";
                                break;
                        }
                        taxAuditFormModel.FIsReturn = "N";
                        taxAuditFormModel.FYear = DateTime.Parse(beginDate).Year;
                        taxAuditFormBLL.Update(taxAuditFormModel, taxAuditAdjustList, taxAudit_SB_ZSXXList);
                        ViewData["NSRBM"] = NSRBM;
                        ViewData["beginDate"] = beginDate;
                        ViewData["endDate"] = endDate;
                        ViewData["jsAlert"] = "操作成功";
                        ViewData["AllowanceClassList"] = allowanceClassBLL.GetModelList("");
                        if (status == "open")
                        {
                            ViewData["FStatus"] = "open";
                            WorkFlow("t_TaxAuditForm", "10", taxAuditFormModel.FTaxAuditId, "start", "");
                        }
                        else
                        {
                            ViewData["FStatus"] = "Save";
                        }

                        return TaxAuditFormEdit(taxAuditFormModel.FTaxAuditId);
                    }
                    catch
                    {
                        //ViewData["NSRBM"] = NSRBM;
                        //ViewData["beginDate"] = beginDate;
                        //ViewData["endDate"] = endDate;
                        ViewData["jsAlert"] = "操作异常";
                        //ViewData["type"] = type;
                        //ViewData["AllowanceClassList"] = allowanceClassBLL.GetModelList("");
                        return TaxAuditFormEdit(taxAuditFormModel.FTaxAuditId);
                    }
            }
            ViewData["NSRBM"] = NSRBM;
            ViewData["beginDate"] = beginDate;
            ViewData["endDate"] = endDate;
            ViewData["jsAlert"] = "操作异常";
            return View("TaxAuditFormEdit", DJ_NSRXXModel);
        }

        public string DelTaxAuditForm(string taxAuditNo)
        {
            string str = "";
            try
            {
                BLL.TaxAuditForm taxAuditFormBLL = new BLL.TaxAuditForm();
                taxAuditFormBLL.Delete(taxAuditNo);
                str = "ok";
            }
            catch (Exception)
            {
                str = "error";
            }
            return str;
        }

        public ActionResult LookEntry(string taxClassAllowanceNo, string fyear, string taxClssNo, string NSRBM, string beginDate, string endDate)
        {
            BLL.VSBZSXX VSBZSXXBLL = new BLL.VSBZSXX();
            BLL.DJ_NSRXX DJ_NSRXXBLL = new BLL.DJ_NSRXX();
            BLL.TaxClassAllowance taxClassAllowanceBLL = new BLL.TaxClassAllowance();
            BLL.TaxClass taxClassBLL = new BLL.TaxClass();
            BLL.HREmpl hrEmplBLL = new BLL.HREmpl();
            DataTable dt = new DataTable();
            List<Model.TaxAuditLookEntry> taxAuditLookEntryList = new List<Model.TaxAuditLookEntry>();

            Model.DJ_NSRXX DJ_NSRXXModel = DJ_NSRXXBLL.GetModelByNSRBM(NSRBM, DateTime.Parse(beginDate).Year.ToString());

            string rejects = VSBZSXXBLL.GetRejectTaxSqlByYear(DateTime.Parse(beginDate).Year.ToString());

            string str = "";
            if (rejects != "" && rejects != "( NULL)     ")
            {
                str += @"  NOT EXISTS (SELECT  ZSXH
         FROM fund.V_SB_ZSXX s WHERE (" + rejects + @")  AND
                                   r.FDataSource = s.FDataSource AND
                                   r.ZSXH = s.ZSXH ) and ";
                str +=  "DATEDIFF(DAY,'" + beginDate + "',RKRQ)>=0 AND DATEDIFF(DAY,'" + endDate + "',RKRQ)<=0";
            }

            else
            {
                str += "DATEDIFF(DAY,'" + beginDate + "',RKRQ)>=0 AND DATEDIFF(DAY,'" + endDate + "',RKRQ)<=0";
            }
            str += " and NSRDZDAH='" + DJ_NSRXXModel.NSRDZDAH + "'";
            if (taxClassAllowanceNo != null && taxClassAllowanceNo != "")
            {
                Model.TaxClassAllowance taxClassAllowanceModel = taxClassAllowanceBLL.GetModel(DateTime.Parse(beginDate).Year, taxClassAllowanceNo);
                str += " and ZSXM_DM='" + taxClassAllowanceModel.FTaxClassNo + "' ";
                if (taxClassAllowanceModel.FSQLCondition != "")
                {
                    str += "and " + taxClassAllowanceModel.FSQLCondition;
                }
                dt = VSBZSXXBLL.GetListByAuditLookEntry(str).Tables[0];
                ViewData["taxClassName"] = taxClassAllowanceModel.FTaxClassAllowanceName;

                List<Model.TaxAuditAdjust> taxAuditAdjustList = OperateSession.getList<Model.TaxAuditAdjust>("TaxAuditAdjustList");
                List<Model.TaxAuditAdjust> q = (from nm in taxAuditAdjustList where nm.FTaxClassAllowanceNo == taxClassAllowanceNo select nm).ToList();
                foreach (Model.TaxAuditAdjust tAA in q)
                {
                    Model.TaxAuditLookEntry tAE = new Model.TaxAuditLookEntry();
                    tAE.se = tAA.FAdjustAmount;
                    tAE.RKRQ = tAA.RKRQ;
                    tAE.isAdjust = "Y";
                    tAE.AdjustNote = tAA.FNote;
                    tAE.AdjustName =  tAA.FEmpName;
                    taxAuditLookEntryList.Add(tAE);
                }
            }
            else
            {
                taxClassBLL.GetModel(taxClssNo);
                str += " and ZSXM_DM='" + taxClssNo + "'";

                dt = VSBZSXXBLL.GetListByAuditLookEntry(str).Tables[0];
                ViewData["taxClassName"] = taxClassBLL.GetModel(taxClssNo).FTaxClassName;
            }

            foreach (DataRow dr in dt.Rows)
            {
                Model.TaxAuditLookEntry tAE = new Model.TaxAuditLookEntry();
                tAE.se = decimal.Parse(dr["se"].ToString());
                tAE.RKRQ = DateTime.Parse(dr["RKRQ"].ToString());
                taxAuditLookEntryList.Add(tAE);
            }

            for (int i = 0; i < taxAuditLookEntryList.Count; i++)
            {
                taxAuditLookEntryList[i].xh = i + 1;
            }

            OperateSession.addList<Model.TaxAuditLookEntry>("taxAuditLookEntryList", taxAuditLookEntryList);

            ViewData["nsrmc"] = DJ_NSRXXModel.NSRMC;
            ViewData["rq1"] = DateTime.Parse(beginDate).ToString("yyyy-MM-dd");
            ViewData["rq2"] = DateTime.Parse(endDate).ToString("yyyy-MM-dd");
            return View(taxAuditLookEntryList);
        }

        public ActionResult LookEntryPartial()
        {
            return PartialView("LookEntryPartial", OperateSession.getList<Model.TaxAuditLookEntry>("taxAuditLookEntryList").OrderBy(nm => nm.RKRQ));
        }

        public string DelTaxAuditAdjust(string fTaxAuditAdjustID)
        {
            try
            {
                List<Model.TaxAuditAdjust> taxAuditAdjustList = OperateSession.getList<Model.TaxAuditAdjust>("TaxAuditAdjustList");
                taxAuditAdjustList = (from nm in taxAuditAdjustList where nm.FTaxAuditAdjustID != fTaxAuditAdjustID select nm).ToList();
                OperateSession.del("TaxAuditAdjustList");
                OperateSession.addList<Model.TaxAuditAdjust>("TaxAuditAdjustList", taxAuditAdjustList);
                return "ok";
            }
            catch
            {
                return "error";
            }
        }

        public string TaxAuditAdjustSave(string fTaxClassAllowanceNo, string rkrq, string fAdjustAmount, string fNote )
        {
            try
            {
                BLL.HREmpl hrEmplBLL = new BLL.HREmpl();
              
                Model.TaxAuditAdjust model = new Model.TaxAuditAdjust();
                model.FTaxClassAllowanceNo = fTaxClassAllowanceNo;
                model.RKRQ = DateTime.Parse(rkrq);
                model.FAdjustAmount = decimal.Round(decimal.Parse(fAdjustAmount),2);
                model.FNote = fNote;
                model.FAdjustDeptNo = OperateSession.get(GlobalConstant.PARAM_DEPTNO);
                model.FAdjustEmpNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);
                model.FEmpName = OperateSession.get(GlobalConstant.PARAM_USERNAME);
                model.FAdjustIP = Common.GenerateUtil.GetClientIPv4Address();
                model.FEntityNo = GlobalConstant.ENTITYNO;
                model.FStatus = "N";
                model.FAdjustDate = DateTime.Now;
                model.FTaxAuditAdjustID = Guid.NewGuid().ToString();

                DataSet ds = hrEmplBLL.GetEmplFromViewByEmplNo(model.FAdjustEmpNo, GlobalConstant.ENTITYNO);

                model.FEmpName = ds.Tables[0].Rows[0]["FEmpName"].ToString();

                BLL.TaxClassAllowance TaxClassAllowanceBLL = new BLL.TaxClassAllowance();
                Model.TaxClassAllowance taxClassAllowanceModel = TaxClassAllowanceBLL.GetModel(DateTime.Parse(rkrq).Year, fTaxClassAllowanceNo);
                if (taxClassAllowanceModel != null)
                {
                    model.FTaxClassAllowanceName = taxClassAllowanceModel.FTaxClassAllowanceName;
                }
     
                List<Model.TaxAuditAdjust> taxAuditAdjustList = OperateSession.getList<Model.TaxAuditAdjust>("TaxAuditAdjustList");
                taxAuditAdjustList.Add(model);
                OperateSession.del("TaxAuditAdjustList");
                OperateSession.addList<Model.TaxAuditAdjust>("TaxAuditAdjustList", taxAuditAdjustList);
                return "ok";
            }
            catch
            {
                return "error";
            }
        }

        public ActionResult TaxAudit_SB_ZSXXListPartial()
        {
            string beginDate = Request.Params["beginDate"];
            string endDate = Request.Params["endDate"];
            string NSRBM = Request.Params["NSRBM"];

            List<Model.TaxAuditAdjust> taxAuditAdjustList = OperateSession.getList<Model.TaxAuditAdjust>("TaxAuditAdjustList");
            BLL.DJ_NSRXX DJ_NSRXXBLL = new BLL.DJ_NSRXX();
            DataSet ds = DJ_NSRXXBLL.GetDataforAudit(beginDate, endDate, DateTime.Parse(beginDate).Year.ToString(), NSRBM);

            DataTable dt = GetShowDate(taxAuditAdjustList, ds.Tables[0], DateTime.Parse(beginDate).Year.ToString());

            return View("TaxAudit_SB_ZSXXListPartial", dt);
        }

        public ActionResult TaxAuditAdjustListPartial()
        {
            int pageIndex = Request.Params["pageIndex"] == null ? 0 : int.Parse(Request.Params["pageIndex"].ToString());
            int pageCount = Request.Params["PageCount"] == null ? 0 : int.Parse(Request.Params["PageCount"].ToString());
            int pageRowSize = Request.Params["pageRowSize"] == null ? 0 : int.Parse(Request.Params["pageRowSize"].ToString());
            int pageRowCount = Request.Params["pageRowCount"] == null ? 0 : int.Parse(Request.Params["pageRowCount"].ToString());
            string callbackArg = DevExpressHelper.CallbackArgument;

            string command = Request.Params["command"] == null ? "" : Request.Params["command"].ToString();

            if (command == "PAGERONCLICK")
            {
                string[] args = callbackArg.Split(new char[1] { '|' });
                string arg = args[args.Count() - 1];

                switch (arg)
                {
                    case "PBN;":
                        {
                            //下一页
                            pageIndex = pageIndex + 2;
                            break;
                        }
                    case "PBP;":
                        {
                            //上一页
                            //pageIndex = pageIndex;
                            break;
                        }
                    case "PBL;":
                        {
                            //最后一页
                            pageIndex = pageCount;
                            break;
                        }
                    case "PBF;":
                        {
                            //第一页
                            pageIndex = 1;
                            break;
                        }
                    default:
                        {
                            //点击数字页码
                            string tempIndex = arg.Replace("PN", "");
                            tempIndex = tempIndex.Replace(";", "");
                            if (RegExp.IsNumeric(tempIndex))
                            {
                                pageIndex = int.Parse(tempIndex) + 1;
                            }
                            break;
                        }

                }
            }
            else
            {
                pageIndex = pageIndex + 1;
            }
            //string NSRMC = Request.Params["NSRMC"];
            //string NSRBM = Request.Params["NSRBM"];
            //string HY_DM = Request.Params["HY_DM"];
            //string FEnterprisePropNo = Request.Params["FEnterprisePropNo"];
            //string FFinancePropNo = Request.Params["FFinancePropNo"];
            //string IsNoFull = Request.Params["IsNoFull"];

            List<Model.TaxAuditAdjust> taxAuditFormList = new List<Model.TaxAuditAdjust>();
            taxAuditFormList = OperateSession.getList<Model.TaxAuditAdjust>("TaxAuditAdjustList");
            return PartialView("TaxAuditAdjustListPartial", taxAuditFormList);
        }

        public ActionResult TaxAuditAdjustIndex(string taxAuditId, string beginDate)
        {
            List<Model.TaxAuditAdjust> taxAuditAdjustList = new List<Model.TaxAuditAdjust>();
            if (taxAuditId != null && taxAuditId != "")
            {
                BLL.TaxAuditAdjust taxAuditAdjustBLL = new BLL.TaxAuditAdjust();
                taxAuditAdjustList = taxAuditAdjustBLL.GetModelList(" FTaxAuditId ='" + taxAuditId + "'");
                ViewData["isshow"] = "Y";
            }
            else
            {
                taxAuditAdjustList = OperateSession.getList<Model.TaxAuditAdjust>("TaxAuditAdjustList");
                ViewData["isshow"] = "N";
            }
            if (taxAuditAdjustList == null)
            {
                taxAuditAdjustList = new List<Model.TaxAuditAdjust>();
            }
            ViewData["taxAuditId"] = taxAuditId;
            ViewData["beginDate"] = beginDate;
            if (taxAuditId == null || taxAuditId == "")
            {
                taxAuditAdjustList = OperateSession.getList<Model.TaxAuditAdjust>("TaxAuditAdjustList");
            }
            else
            {
                OperateSession.addList<Model.TaxAuditAdjust>("TaxAuditAdjustList", taxAuditAdjustList);
            }
            return View(taxAuditAdjustList); 
        }

        public ActionResult TaxAuditAdjustEdit(string taxAuditId, string beginDate)
        {
            Model.TaxAuditAdjust taxAuditAdjustModel = new Model.TaxAuditAdjust();

            BLL.TaxClassAllowance taxClassAllowanceBLL = new BLL.TaxClassAllowance();

            BLL.TaxAuditForm taxAuditFormBLL = new BLL.TaxAuditForm();
            Model.TaxAuditForm model = new Model.TaxAuditForm();
            if (taxAuditId != null && taxAuditId != "")
            {
                model = taxAuditFormBLL.GetModel(taxAuditId);
            }
            else if (beginDate != null && beginDate != "")
            {
                model.FYear = DateTime.Parse(beginDate).Year;
            }
            else
            {
                model.FYear = 0;
            }

            List<Model.TaxClassAllowance> taxClassAllowanceList = taxClassAllowanceBLL.GetModelList(" FYear = '" + model.FYear + "'");
           
            ViewData["taxClassAllowanceList"] = taxClassAllowanceList;
           
            return View(taxAuditAdjustModel);
        }

        public ActionResult TaxAuditFormPrint(string NSRBM, string beginDate, string endDate)
        {
            ViewData["NSRBM"] = NSRBM;
            ViewData["beginDate"] = beginDate;
            ViewData["endDate"] = endDate;
            XtraReport x2 = new EnterpriseFund.Views.TaxAuditForm.Print2();
            ViewData["x"] = x2;
            //DataSet ds = new DataSet();
            //BLL.TaxAuditForm taxAuditFormBLL = new BLL.TaxAuditForm();
            //ds = taxAuditFormBLL.GetDataforAuditForSave(beginDate, endDate, DateTime.Parse(beginDate).Year.ToString(), NSRBM);
            //DataTable dt = GetPintData();
            //BLL.DJ_NSRXX DJ_NSRXXBLL = new BLL.DJ_NSRXX();
            //Model.DJ_NSRXX DJ_NSRXXModel = DJ_NSRXXBLL.GetModelByNSRBM(NSRBM, DateTime.Parse(beginDate).Year.ToString());
            //DataSet nds = new DataSet();
            //foreach (DataRow dr in ds.Tables[0].Rows)
            //{
            //    DataRow ndr = dt.NewRow();
            //    ndr["SE"] = dr["se"];
            //    ndr["TaxItem"] = dr["FTaxClassAllowanceName"];
            //    ndr["PZHM"] = dr["YZPZXH"];
            //    ndr["BZ"] = dr["bz"];
            //    ndr["RKRQ"] = dr["RKRQ"];
            //    ndr["NSRMC"] = DJ_NSRXXModel.NSRMC;
            //    ndr["NSRSBH"] = DJ_NSRXXModel.NSRSBH;
            //    ndr["NSBM"] = DJ_NSRXXModel.NSRBM;
            //    ndr["CWFZR"] = DJ_NSRXXModel.CWFZRMC;
            //    ndr["CWFZRDH"] = DJ_NSRXXModel.CWFZRDH;
            //    ndr["QYFZR"] = DJ_NSRXXModel.FDDBRMC;
            //    ndr["FZRDH"] = DJ_NSRXXModel.FRDH;
            //    dt.Rows.Add(ndr);
            //}
            //nds.Tables.Add(dt);
            //nds.Tables.Add(GetPintData());
            //ViewData["data"] = nds;
            return View();
        }

        public DataTable GetPintData()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("NSRMC");
            dt.Columns.Add("NSRSBH");
            dt.Columns.Add("NSBM");
            dt.Columns.Add("QYFZR");
            dt.Columns.Add("FZRDH");
            dt.Columns.Add("FZRSJH");
            dt.Columns.Add("CWFZRDH");
            dt.Columns.Add("CWFZR");
            dt.Columns.Add("CWFZRSJH");
            dt.Columns.Add("JBRY");
            dt.Columns.Add("JBRYDH");
            dt.Columns.Add("JBRYSJH");
            dt.Columns.Add("TaxItem");
            dt.Columns.Add("RKRQ");
            dt.Columns.Add("SE");
            dt.Columns.Add("PZHM");
            dt.Columns.Add("BZ");
            return dt;
        }

        public ActionResult TaxAuditFormPrintPartial()
        {
            XtraReport x2 = new EnterpriseFund.Views.TaxAuditForm.Print2();
            string NSRBM = Request["NSRBM"];
            string beginDate = Request["BeginDate"];
            string endDate = Request["EndDate"];
            DataSet ds = new DataSet();
            BLL.TaxAuditForm taxAuditFormBLL = new BLL.TaxAuditForm();
            ds = taxAuditFormBLL.GetDataforAuditForSave(beginDate, endDate, DateTime.Parse(beginDate).Year.ToString(), NSRBM);

            BLL.DJ_NSRXX DJ_NSRXXBLL = new BLL.DJ_NSRXX();
            Model.DJ_NSRXX DJ_NSRXXModel = DJ_NSRXXBLL.GetModelByNSRBM(NSRBM, DateTime.Parse(beginDate).Year.ToString());
            DataSet nds = new DataSet();


            var q = (from nm in ds.Tables[0].AsEnumerable() group nm by nm.Field<string>("FTaxClassAllowanceName") into g select new { taxname = g.Key });

            foreach (var v in q)
            {
                DataRow[] drList = ds.Tables[0].Select("FTaxClassAllowanceName='" + v.taxname + "'", "RKRQ");
                DataTable dt = GetPintData();
                foreach (DataRow dr in drList)
                {
                    DataRow ndr = dt.NewRow();
                    ndr["SE"] = dr["se"];
                    ndr["TaxItem"] = dr["FTaxClassAllowanceName"];
                    ndr["PZHM"] = dr["YZPZXH"];
                    ndr["BZ"] = dr["bz"];
                    ndr["RKRQ"] = DateTime.Parse(dr["RKRQ"].ToString()).ToString("yyyy-MM-dd");
                    ndr["NSRMC"] = DJ_NSRXXModel.NSRMC;
                    ndr["NSRSBH"] = DJ_NSRXXModel.NSRSBH;
                    ndr["NSBM"] = DJ_NSRXXModel.NSRBM;
                    ndr["CWFZR"] = DJ_NSRXXModel.CWFZRMC;
                    ndr["CWFZRDH"] = DJ_NSRXXModel.CWFZRDH;
                    ndr["QYFZR"] = DJ_NSRXXModel.FDDBRMC;
                    ndr["FZRDH"] = DJ_NSRXXModel.FRDH;
                    ndr["JBRY"] = DJ_NSRXXModel.BSRMC;
                    ndr["JBRYDH"] = DJ_NSRXXModel.BSRYDH;
                    ndr["JBRYSJH"] = DJ_NSRXXModel.BSR_YDDHHM;
                    ndr["FZRSJH"] = DJ_NSRXXModel.FR_YDDHHM;
                    ndr["CWFZRSJH"] = DJ_NSRXXModel.CW_YDDHHM;
                    dt.Rows.Add(ndr);
                    if (dt.Rows.Count == 14)
                    {
                        XtraReport x = new EnterpriseFund.Views.TaxAuditForm.Print2();
                        x.DataSource = dt;
                        x.CreateDocument();
                        foreach (Page p in x.Pages)
                        {
                            x2.Pages.Add(p);
                        }
                        dt.Rows.Clear();
                    }
                }

                int counts = dt.Rows.Count;
                if (counts != 0)
                {
                    if (counts % 14 != 0)
                    {
                        for (int i = 0; i < 14 - (counts % 14); i++)
                        {
                            DataRow ndr = dt.NewRow();
                            dt.Rows.Add(ndr);
                        }
                    }

                    XtraReport x3 = new EnterpriseFund.Views.TaxAuditForm.Print2();
                    x3.DataSource = dt;
                    x3.CreateDocument();
                    foreach (Page p in x3.Pages)
                    {
                        x2.Pages.Add(p);
                    }
                }
            }


            //XtraReport x = new EnterpriseFund.Views.TaxAuditForm.Print2();
            //x.DataSource = dt;
            //x.CreateDocument();
            //foreach (Page p in x.Pages)
            //{
            //    x2.Pages.Add(p);
            //}

            ViewData["x"] = x2;

            return PartialView("TaxAuditFormPrintPartial");
        }

    }
}
